﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MarginTrading.Services;
using MarginTrading.Entity;
using Microsoft.Reporting.WinForms;
using MarginTrading.Common;


namespace MarginTrading.Forms
{
    public partial class StockExposure : Form
    {
        public StockExposure()
        {
            InitializeComponent();
        }

        private void StockExposure_Load(object sender, EventArgs e)
        {
            //LoadReport("DSA-710032955-VN-00");
            //this.reportViewer1.RefreshReport();
            try
            {
                DataTable advisor = AdvisorServices.GetAdvisorCollectionDataTable();
                DataRow dr = advisor.NewRow();
                dr["CODE"] = "All";
                advisor.Rows.InsertAt(dr, 0);
                AdvisorComboBox.DisplayMember = "CODE";
                AdvisorComboBox.ValueMember = "CODE";
                AdvisorComboBox.DataSource = advisor;
            }
            catch (Exception x)
            {
            }


        }


        private void LoadReport(string sAdvisor)
        {
            try
            {

                Config AgentCodeConfig = ConfigServices.GetConfigByName("Agent Code");

                ReportDataSource ds = new ReportDataSource();
                ds.Name = "master";
                ds.Value = ReportServices.GetStockExposure(AgentCodeConfig.Value, sAdvisor);


                this.reportViewer1.LocalReport.ReportPath = "StockExposure.rdlc";
                this.reportViewer1.LocalReport.DataSources.Clear();
                this.reportViewer1.LocalReport.DataSources.Add(ds);

                
                string AgentCode = "cts";
                if (AgentCodeConfig != null)
                {
                    AgentCode = AgentCodeConfig.Value;
                }

                //TODO:Remove this 
                AgentCode = Reports.AGENT_CODE;

                this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] {
                        new ReportParameter("ImageLink",AgentCode.ToLower()),
                        new ReportParameter("CompanyName",Reports.COMPANY_NAME),
                        new ReportParameter("AdvisorID",sAdvisor)});

                this.reportViewer1.RefreshReport();
                reportViewer1.SetDisplayMode(DisplayMode.PrintLayout);
                reportViewer1.ZoomMode = ZoomMode.Percent;
                reportViewer1.ZoomPercent = 100;
            }
            catch (Exception e)
            {

            }

        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                LoadReport(AdvisorComboBox.SelectedValue.ToString());
            }
            catch (System.Exception ex)
            {
            	
            }
            
        }

    }
}
